#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>
#define print1 1    //0001
#define print2 1<<1 //0010
#define print3 1<<2 //0100
#define print4 1<<3 //1000

void print(int print)
{
    if(print&print1){printf("print1\n");}
    if(print&print2){printf("print2\n");}
    if(print&print3){printf("print3\n");}
    if(print&print4){printf("print4\n");}
}


int main()
{
   //系统调用函数进行文件操作
   //print(print1); 
   //print(print1|print2); 
   //print(print2|print3|print4); 
   //print(print1|print2|print3|print4); 
    //int fd = open("log.txt",O_WRONLY|O_CREAT|O_TRUNC);
    //umask(0000);
    printf("stdin fd:%d\n",stdin->_fileno);
    printf("stdout fd:%d\n",stdout->_fileno);
    printf("stderr fd:%d\n",stderr->_fileno);
    int fd = open("log.txt",O_WRONLY|O_CREAT|O_APPEND,0666);
    if(fd==-1)
    {
        perror("open");
        return 1;
    }
    
    printf("log.txt fd:%d\n",fd);
    const char *msg={"Hello linux file\n"};
    write(fd,msg,strlen(msg));

    close(fd);

















    ////c语言库函数操作文件打开文件
    ////FILE *fp = fopen("log.txt","w");
    //FILE *fp = fopen("log.txt","a");
    //if(fp==NULL)
    //{
    //    perror("fopen");
    //    return 1;
    //}

    ////文件操作
    //const char *msg={"aaa\n"};
    //fputs(msg,fp);
    //
    ////for(int i =0;i<10;i++)
    ////{
    ////    fputs(msg,fp);
    ////}

    ////关闭文件
    //fclose(fp);
    //return 0;
}
